package cn.school.mybatis.test;

import cn.school.mybatis.dao.AdminDao;
import cn.school.mybatis.pojo.Admin;
import cn.school.mybatis.pojo.Grade;
import cn.school.mybatis.pojo.Student;
import cn.school.mybatis.service.AdminService;
import cn.school.mybatis.service.GradeService;
import cn.school.mybatis.service.StudentService;
import org.junit.jupiter.api.Test;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class SMtest2 {
    @Autowired
    private StudentService studentService;
    @Autowired
    private GradeService gradeService;
    @Autowired
    private AdminService adminService;

    @Test
    public void test(){
        Student student=studentService.get(1);
        System.out.println(student);
    }

    @Test
    public void test2(){
        Student student2= new Student("李狗蛋8282", "男", "128282", "2338282", "ligoudan8282", 3, "2020-07-04", "巢湖", "2020-07-05", "合肥包河","123456","pic");
        System.out.println(student2);
        System.out.println(studentService.add(student2));
    }
    @Test
    public void test3(){
        List<Grade> lists=gradeService.searchAll();
        for (Grade g:lists){
            System.out.print(g);
        }
    }

    @Test
    public void test4(){
        //ApplicationContext ac=new ClassPathXmlApplicationContext("spring-mybatis.xml");
        //SqlSessionTemplate t=(SqlSessionTemplate)ac.getBean("sessionTemplate");
        //GradeDao dao=t.getMapper(GradeDao.class);
        //List<Grade> list = dao.searchAll();

        Map map=new HashMap();
        map.put("pageNo", 1);
        map.put("pageSize", 100);
        map.put("orderBy", "stuno asc");
        List<Student> lists = studentService.search(1,10,map);
        for(Student s:lists) {
            System.out.println(s);
        }
    }

    @Test
    public void test5(){
        List<Admin> lists=adminService.searchAll();
        for (Admin a:lists){
            System.out.print(a);
        }
    }

    @Test
    public void test6(){
        List<Admin> lists=adminService.searchAdmin("admin","");
        for (Admin a:lists){
            System.out.print(a);
        }
    }

    @Test
    public void test7(){
        System.out.println(adminService.add(new Admin("admin30","123456"))>0);
    }
    @Test
    public void test8() {
        Student student=studentService.get(1);
        System.out.println(student);

       Student student2= new Student("李狗蛋828", "男", "12828", "233828", "ligoudan828", 3, "2020-07-04", "巢湖", "2020-07-05", "合肥包河","123456","pic");
        System.out.println(student2);
        System.out.println(studentService.add(student2));
    }

    public static void main(String[] args) {

        AdminService adminService=new AdminService();
        List<Admin> lists=adminService.searchAdmin("admin","");
        for (Admin a:lists){
            System.out.print(a);
        }
    }

}
